<template>
  <div>
    <FilterTable ref="table" columnsRef="fyhOrderLog" :columns="columns" :dataSource="tableList" :onColumnsChange="columns => (this.columns = columns)" :onSyncTableData="syncTableFun"></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button type="primary" @click="closeOrderLog">确定</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import dictCode from '@/utils/dictCode';
import { queryLog } from '@/api/repair/repairReception/repairBusinessManger';
import { getDealerUser } from '@/api/repair/repairReception/customer';
import { getBxgsSelect} from '@/api/repair/repairReception/customer';
import { searchRoleByCode } from '@/api/common/empSelect/index';

export default {
  name: 'orderLogModel',
  mixins: [dictionary],
  props: ['list'],
  data() {
    return {
      columns: this.createTableColumns(),
      tableList: []
    };
  },

  mounted() {
    this.queryOrderLog();
    this.initTableInfo();
    this.getBxgsSelect();
  },

  methods: {
    async getBxgsSelect() {
      let all=[];
      let consultant = { role: dictCode.SERVICE_CONSULTANT }; // 服务顾问
      let consultantRes = await searchRoleByCode(consultant);
      let man =consultantRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      man.forEach(x => {all.push(x);});
      let res = await getBxgsSelect();
      let ress = res.data.map(x => ({ value: x.INSURATION_CODE, text: x.INSURATION_NAME }));
      ress.forEach(x =>{all.push(x)});
      this.columns.find(x => x.dataIndex === 'OLD_VALUE').editItems = all;
         this.columns.find(x => x.dataIndex === 'NEW_VALUE').editItems = all;
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '业务名称',
          dataIndex: 'COLUMN_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '变更内容',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '说明',
          dataIndex: 'TABLE_VIEW_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '变更类型',
          dataIndex: 'LOG_TYPE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '原值',
          dataIndex: 'OLD_VALUE',
          sorter: true,
          filter: true,
          filterType: 'select',
          filterItems: [],
          dictItems:[],
           editItems:[]
        },
        {
          title: '新值',
          dataIndex: 'NEW_VALUE',
          sorter: true,
          filter: true,
          filterType: 'select',
          filterItems: [],
          dictItems:[],
          editItems:[]
        },
        {
          title: '操作人',
          dataIndex: 'OPERATOR',
          sorter: true,
          filter: true,
          editType: 'select',
          editItems: []
        },
        {
          title: '操作时间',
          dataIndex: 'OPERATE_TIME',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd HH:mm:ss'
        }
      ];
    },

    createBaseTable() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    },
    async initTableInfo() {
      const res = await getDealerUser();
      this.columns.find(x => x.dataIndex === 'OPERATOR').editItems = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
    },

    // 日志查询
    async queryOrderLog() {
      const roNo = this.list[0].RO_NO;
      const res = await queryLog(roNo);
      console.log(res, 'res');
      this.tableList = res.data;
    },

    syncTableFun() {},
    closeOrderLog() {
      this.$emit('closeOrderLog', false);
    }
  }
};
</script>

<style lang="less"></style>
